<template>
    <div>
        <el-dialog
            :title="!form.id ? '新增' : '修改'"
            :visible.sync="visible"
            :close-on-click-modal="false">

            <div class="table_form_wrap">
                <el-form ref="form" :model="form" :rules="rules" @keyup.enter.native="handleSubmit()" label-width="120px">
                    <el-form-item label="会员ID" prop="memberId">
                        <el-input placeholder="" v-model="form.memberId" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="累计消费金额" prop="consumeAmount">
                        <el-input placeholder="" v-model="form.consumeAmount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="累计优惠金额" prop="couponAmount">
                        <el-input placeholder="" v-model="form.couponAmount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="订单数量" prop="orderCount">
                        <el-input placeholder="" v-model="form.orderCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="优惠券数量" prop="couponCount">
                        <el-input placeholder="" v-model="form.couponCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="评价数" prop="commentCount">
                        <el-input placeholder="" v-model="form.commentCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="退货数量" prop="returnOrderCount">
                        <el-input placeholder="" v-model="form.returnOrderCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="登录次数" prop="loginCount">
                        <el-input placeholder="" v-model="form.loginCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="关注数量" prop="attendCount">
                        <el-input placeholder="" v-model="form.attendCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="粉丝数量" prop="fansCount">
                        <el-input placeholder="" v-model="form.fansCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="收藏的商品数量" prop="collectProductCount">
                        <el-input placeholder="" v-model="form.collectProductCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="收藏的专题活动数量" prop="collectSubjectCount">
                        <el-input placeholder="" v-model="form.collectSubjectCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="收藏的评论数量" prop="collectCommentCount">
                        <el-input placeholder="" v-model="form.collectCommentCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="邀请的朋友数量" prop="inviteFriendCount">
                        <el-input placeholder="" v-model="form.inviteFriendCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="创建时间" prop="ctime">
                        <el-input placeholder="" v-model="form.ctime" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="最后更新时间" prop="utime">
                        <el-input placeholder="" v-model="form.utime" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <!--
                    <el-form-item label="状态" prop="status">
                        <el-radio-group v-model="form.status">
                            <el-radio-button :label="1">正常</el-radio-button>
                            <el-radio-button :label="0">锁定</el-radio-button>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="薪资" prop="salary">
                        <el-input-number v-model="form.salary" :precision="2" :step="0.01" :min="0.00" style="width: 80%;"></el-input-number>
                    </el-form-item>
                    <el-form-item label="排序" prop="sort">
                        <el-input-number v-model="form.sort" :min="1" :max="10000" placeholder="排序"></el-input-number>
                    </el-form-item>
                    <el-form-item label="性别" prop="sex">
                        <el-select v-model="form.sex" placeholder="请选择">
                            <el-option label="男" value="男"></el-option>
                            <el-option label="女" value="女"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="生日" prop="birthday">
                        <el-date-picker
                            v-model="form.birthday"
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-dd"
                            style="width: 63%;">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="备注" prop="remarks">
                        <el-input v-model="form.remarks" type="textarea" :rows="4" placeholder="请输入内容" style="width: 80%;"></el-input>
                    </el-form-item>
                    -->

                </el-form>
            </div>


            <div slot="footer" class="dialog-footer">
                <el-button @click="visible = false">取 消</el-button>
                <el-button @click="handleSubmit()" type="primary" :submitLoading="submitLoading">提 交</el-button>
            </div>

        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            visible: false,
            submitLoading: false,

            form: {
                memberId: null,
                consumeAmount: null,
                couponAmount: null,
                orderCount: null,
                couponCount: null,
                commentCount: null,
                returnOrderCount: null,
                loginCount: null,
                attendCount: null,
                fansCount: null,
                collectProductCount: null,
                collectSubjectCount: null,
                collectCommentCount: null,
                inviteFriendCount: null,
                ctime: null,
                utime: null
            },
            rules: {
                memberId: [
                    { required: true, message: '会员ID不能为空', trigger: 'blur' }
                ],
                consumeAmount: [
                    { required: true, message: '累计消费金额不能为空', trigger: 'blur' }
                ],
                couponAmount: [
                    { required: true, message: '累计优惠金额不能为空', trigger: 'blur' }
                ],
                orderCount: [
                    { required: true, message: '订单数量不能为空', trigger: 'blur' }
                ],
                couponCount: [
                    { required: true, message: '优惠券数量不能为空', trigger: 'blur' }
                ],
                commentCount: [
                    { required: true, message: '评价数不能为空', trigger: 'blur' }
                ],
                returnOrderCount: [
                    { required: true, message: '退货数量不能为空', trigger: 'blur' }
                ],
                loginCount: [
                    { required: true, message: '登录次数不能为空', trigger: 'blur' }
                ],
                attendCount: [
                    { required: true, message: '关注数量不能为空', trigger: 'blur' }
                ],
                fansCount: [
                    { required: true, message: '粉丝数量不能为空', trigger: 'blur' }
                ],
                collectProductCount: [
                    { required: true, message: '收藏的商品数量不能为空', trigger: 'blur' }
                ],
                collectSubjectCount: [
                    { required: true, message: '收藏的专题活动数量不能为空', trigger: 'blur' }
                ],
                collectCommentCount: [
                    { required: true, message: '收藏的评论数量不能为空', trigger: 'blur' }
                ],
                inviteFriendCount: [
                    { required: true, message: '邀请的朋友数量不能为空', trigger: 'blur' }
                ],
                ctime: [
                    { required: true, message: '创建时间不能为空', trigger: 'blur' }
                ],
                utime: [
                    { required: true, message: '最后更新时间不能为空', trigger: 'blur' }
                ],
            }
        }
    },

    methods: {
        init(id) {
            const refs = this.$refs
            // 情况表单数据
            this.form.id = id || null
            this.visible = true

            this.$nextTick(() => {
                refs['form'].resetFields()
                if(this.form.id) {
                    this.getInfo(this.form.id)
                }
            })
        },

        /**
         * 详细信息
         */
        async getInfo(id) {
            if (id) {
                const res = await this.$http({
                    url: '/mall/umsmemberstatisticsinfo/info/' + id,
                    method: 'GET'
                })
                this.form = Object.assign({}, res.data)
            }
        },

        /**
         * 提交表单
         */
        async handleSubmit() {
            const refs = this.$refs
            this.submitLoading = true
            const valid = await refs['form'].validate().catch(() => {})
            if(valid) {
                const res = await this.$http({
                    url: `/mall/umsmemberstatisticsinfo/${!this.form.id ? 'save' : 'update'}`,
                    method: 'POST',
                    data: this.form
                })
                if (this.ResultMessage(res)) {
                    this.$emit('refreshDataList')
                    this.submitLoading = false
                    this.visible = false
                } else {
                    this.submitLoading = false
                }
            } else {
                this.submitLoading = false
            }
        }

    }
};
</script>

<style lang="scss" scoped></style>
